<template>
  <div class="dialog-wrap-code">
    <el-dialog :visible.sync="dialogVisible_owner_code.show" center>
      <div class="show-title">标识ID：{{ sn_seled }}</div>
      <!-- <div class="show-title">中心编码：{{ owner_code }}</div> -->
      <!-- 2 -->
      <el-form
        :inline="true"
        :model="form2ruleform"
        ref="form2"
        :rules="form2rules"
        class="demo-form-inline form2"
      >
        <el-form-item label="中心编码" prop="owner_code">
          <el-input
            v-model="form2ruleform.owner_code"
            placeholder
            style="width: 380px"
          ></el-input>
          <br />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="small" @click="fnSubmit('form2')"
            >修改</el-button
          ></el-form-item
        >
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { getData, postData } from "@/request/http";
export default {
  name: "audit",
  props: {
    dialogVisible_owner_code: {
      type: Object,
      default() {
        return {
          show: false,
        };
      },
    },
    sn: {
      type: String,
      default: "",
    },
    owner_code: {
      type: Number,
      default: "",
    },
  },
  data() {
    const validatorCode = (rule, value, callback) => {
      if (value.length > 64) {
        callback(new Error("编码字符长度最大64"));
      } else {
        callback();
      }
    };
    return {
      sn_seled: "",
      form2ruleform: {
        owner_code: "",
      },
      form2rules: {
        owner_code: [
          {
            required: false,
            message: "请输入中心编码",
          },
          {
            trigger: "blur",
            validator: validatorCode,
          },
        ],
      },
    };
  },
  mounted() {
    // this.owner_code_seled = this.owner_code;
    this.form2ruleform.owner_code = this.owner_code;
  },
  watch: {
    sn: {
      handler(newVal) {
        this.sn_seled = newVal;
      },
      immediate: true,
    },
    // owner_code: {
    //   handler(newVal) {
    //     this.owner_code_seled = newVal;
    //   },
    //   deep: true,
    //   immediate: true,
    // },
  },
  methods: {
    //修改
    fnSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          postData("/adminweb/host/update/ownercode", {
            sn: this.sn_seled,
            owner_code: this.form2ruleform.owner_code,
          })
            .then((res) => {
              if (res.code == 0) {
                this.$message.success("修改成功");
                this.$emit("refreshList");
              } else {
                this.$message.error(res.code + "，" + res.msg);
              }
            })
            .catch((res) => {
              this.$message.error(res.code + "，" + res.msg);
            });
        } else {
          return false;
        }
      });
    },
  },
};
</script>

<style scoped>
.dialog-wrap >>> .el-dialog {
  height: 600px;
  overflow-y: scroll;
}
.btn-group {
  margin: 10px 0;
}
.show-title {
  margin-bottom: 10px;
  font-weight: 600;
}
.dialog-wrap >>> .el-form--inline .el-form-item__label {
  display: block;
}
.dialog-wrap >>> .el-form-item {
  width: 100% !important;
  display: flex;
}

.dialog-wrap >>> .el-button {
  margin-left: 30px;
}
</style>
